package com.lry.jvm.classfile.attributes;

import com.lry.jvm.classfile.ClassReader;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data
public class InnerClass implements AttributeInfo {

    private int numOfClasses;//u2
    private InnerClassInfo[] innerClassInfos;

    @Override
    public void readInfo(ClassReader reader) {
        numOfClasses = reader.nextU2ToInt();
        innerClassInfos = new InnerClassInfo[numOfClasses];
        for(int i=0;i<numOfClasses;i++){
            innerClassInfos[i] = readInnerClassInfo(reader);
        }
    }

    private InnerClassInfo readInnerClassInfo(ClassReader reader){
        InnerClassInfo innerClassInfo = new InnerClassInfo();
        innerClassInfo.setInnerClassInfoIndex(reader.nextU2ToInt());
        innerClassInfo.setOuterClassInfoIndex(reader.nextU2ToInt());
        innerClassInfo.setInnerNameIndex(reader.nextU2ToInt());
        innerClassInfo.setInnerClassAccessFlags(reader.nextU2ToInt());
        return innerClassInfo;
    }

    @Setter
    @Getter
    @Data
    class InnerClassInfo{
        private int innerClassInfoIndex;//u2 内部类的符号引用
        private int outerClassInfoIndex;//u2 宿主类的符号引用
        private int innerNameIndex;//u2 内部类的名字
        private int innerClassAccessFlags;
    }
}
